﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using DTO;
using AutoMapper;

namespace DAO
{
    public class PhieuMuonRepository
    {

        public int LayMaPhieuMuonMax()
        {
            QLTVEntities contex = ContextFactory.GetInstance();
            int maphieu = contex.PHIEU_MUONList.Max(s => s.MaPhieuMuon);
            return maphieu;
        }

        public DataTable ThongKeTinhHinhMuonSachTheoTheLoai()
        {
            QLTVEntities context = new QLTVEntities();
            DataTable thongKe = new DataTable();
            var query = from sach in context.SACHList
                        from phieuMuon in context.PHIEU_MUONList
                        from chiTietPM in context.CT_PHIEU_MUONList
                        from theLoai in context.THE_LOAIList
                        where chiTietPM.MaSach == sach.MaSach && sach.MaTheLoai == theLoai.MaTheLoai
                        && chiTietPM.MaPhieuMuon == phieuMuon.MaPhieuMuon
                        group sach by  theLoai.MaTheLoai into groupTL
                        select new                         
                        {                         
                          SoLuongMuon=groupTL.Count()
                        };
            return thongKe;
                        

        }

    }
}
